package ru.amse.ilyin.diagram.impl;

import ru.amse.ilyin.diagram.Element;
import ru.amse.ilyin.diagram.Link;
import ru.amse.ilyin.diagram.Renderer;

/**
 * Implementation of {@link Link} interface.
 * Drawn as a straight line.
 *
 * @author Alexander Ilyin
 */
public class LinkImpl implements Link {
	private final AbstractElement first;
	
	private final AbstractElement second;
	
	/**
	 * Creates new link. Elements connected with this link 
	 * are specified.
	 * 
	 * @param first first element
	 * @param second second element
	 */
	public LinkImpl(
			AbstractElement first, 
			AbstractElement second
	) {
		this.first = first;
		this.second = second;
	}

	public void draw(Renderer renderer) {
		renderer.drawLine(
				first.getCenter().x, 
				first.getCenter().y, 
				second.getCenter().x, 
				second.getCenter().y
		);
	}

	Element getFirstElement() {
		return first;
	}

	Element getSecondElement() {
		return second;
	}
}
